package org.kabeja.parser.objects;

import org.kabeja.dxf.DXFConstants;
import org.kabeja.dxf.objects.DXFDictionary;
import org.kabeja.dxf.objects.DXFObject;
import org.kabeja.parser.DXFValue;

/**
 * @author shutao
 * @since 2022/4/25 12:11
 */
public class DXFDictionaryHandler extends AbstractDXFObjectHandler {
    public final int GROUPCODE_RECORD_NAME = 3;
    public final int GROUPCODE_RECORD_ID = 350;
    protected DXFDictionary dictionary;
    protected String objectName;
    protected boolean rootDictionaryParsed = false;

    public DXFDictionaryHandler() {
    }

    @Override
    public void endObject() {
    }

    @Override
    public DXFObject getDXFObject() {
        return this.dictionary;
    }

    @Override
    public String getObjectType() {
        return DXFConstants.OBJECT_TYPE_DICTIONARY;
    }

    @Override
    public void parseGroup(int var1, DXFValue var2) {
        switch(var1) {
            case GROUPCODE_RECORD_NAME:
                this.objectName = var2.getValue();
                break;
            case GROUPCODE_RECORD_ID:
                this.dictionary.putDXFObjectRelation(this.objectName, var2.getValue());
                break;
            default:
                super.parseCommonGroupCode(var1, var2, this.dictionary);
        }
    }

    @Override
    public void startObject() {
        if (this.rootDictionaryParsed) {
            this.dictionary = new DXFDictionary();
        } else {
            this.dictionary = this.doc.getRootDXFDictionary();
            this.rootDictionaryParsed = true;
        }
    }
}
